import axios from "axios";
import { baseURL } from '../config/index';

const instance = axios.create({
  baseURL,
  timeout: 20000,
  headers: {
    'Content-Type': 'application/json',
  },
  
});

// 请求拦截器
instance.interceptors.request.use(
  (config) => {
    // 获取本地存储的 token
    const token = localStorage.getItem('token');

    // 将 token 添加到请求头部
    if (token) {
      config.headers['token']=token;
    }

    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

// 响应拦截器
instance.interceptors.response.use(
  (response) => {
    return response;
  },
  (error) => {
    return Promise.reject(error);
  }
);

export default instance;
